/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hello.sandbox.entity.location;

import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

/*
 * created by BlackBoxing at 2022/03/05
 * */
public class BLocation implements Parcelable {

  private double mLatitude = 0.0;
  private double mLongitude = 0.0;
  private double mAltitude = 0.0f;
  private float mSpeed = 0.0f;
  private float mBearing = 0.0f;
  private float mAccuracy = 0.0f;
  //    private float mHorizontalAccuracyMeters = 0.0f;
  //    private float mVerticalAccuracyMeters = 0.0f;
  //    private float mSpeedAccuracyMetersPerSecond = 0.0f;
  //    private float mBearingAccuracyDegrees = 0.0f;

  @Override
  public int describeContents() {
    return 0;
  }

  @Override
  public void writeToParcel(Parcel dest, int flags) {
    dest.writeDouble(this.mLatitude);
    dest.writeDouble(this.mLongitude);
    dest.writeDouble(this.mAltitude);
    dest.writeFloat(this.mSpeed);
    dest.writeFloat(this.mBearing);
    dest.writeFloat(this.mAccuracy);
  }

  public double getLatitude() {
    return mLatitude;
  }

  public double getLongitude() {
    return mLongitude;
  }

  public BLocation() {}

  public BLocation(double latitude, double mLongitude) {
    this.mLatitude = latitude;
    this.mLongitude = mLongitude;
  }

  public BLocation(Parcel in) {
    this.mLatitude = in.readDouble();
    this.mLongitude = in.readDouble();
    this.mAltitude = in.readDouble();
    this.mAccuracy = in.readFloat();
    this.mSpeed = in.readFloat();
    this.mBearing = in.readFloat();
  }

  public boolean isEmpty() {
    return mLatitude == 0 && mLongitude == 0;
  }

  public static final Parcelable.Creator<BLocation> CREATOR =
      new Parcelable.Creator<BLocation>() {
        @Override
        public BLocation createFromParcel(Parcel source) {
          return new BLocation(source);
        }

        @Override
        public BLocation[] newArray(int size) {
          return new BLocation[size];
        }
      };

  @Override
  public String toString() {
    return "BLocation{"
        + "latitude: "
        + mLatitude
        + ", longitude: "
        + mLongitude
        + ", altitude: "
        + mAltitude
        + ", speed: "
        + mSpeed
        + ", bearing: "
        + mBearing
        + ", accuracy: "
        + mAccuracy
        + '}';
  }

  public Location convert2SystemLocation() {
    Location location = new Location(LocationManager.GPS_PROVIDER);
    location.setLatitude(mLatitude);
    location.setLongitude(mLongitude);
    location.setSpeed(mSpeed);
    location.setBearing(mBearing);
    location.setAccuracy(40f);
    location.setTime(System.currentTimeMillis());
    Bundle extraBundle = new Bundle();
    // GPS satellite number
    int satelliteCount = 10;
    extraBundle.putInt("satellites", satelliteCount);
    extraBundle.putInt("satellitesvalue", satelliteCount);
    location.setExtras(extraBundle);
    return location;
  }
}
